﻿// 文件名：引用用于结构
// 创建时间：2021/6/22/星期二 16:15:21

#include <iostream>
using namespace std;
#include<string>
struct free_throws
{
	string name;
	int made;
	int attempts;
	float percent;
};
void display(const free_throws &ft);
void set_pc(free_throws &ft);
free_throws & accumulate(free_throws & target, const free_throws & source);


int main()
{
	free_throws one = {"one",13,14};
	free_throws two = { "two",13,14 };
	free_throws three = { "three",13,14 };
	free_throws four = { "four",13,14 };
	free_throws five = { "five",13,14 };
	free_throws team = { "team",13,14 };

	free_throws dup;
	set_pc(one);
	display(one);
	accumulate(team, one);
	display(team);
	
	display(accumulate(team, one));
	accumulate(accumulate(team, three), four);
	display(team);

	dup = accumulate(team, five);
	cout << "Displaying team:\n";
	display(team); 
	cout << "Displyaing dup after assignment:\n";
	display(dup);
	set_pc(four);
	accumulate(dup, five) = four;
	cout << "Displaying dup after ill_advised assignment:\n";
	display(dup);

	system("pause");
	return 0;
}

void display(const free_throws &ft)
{
	cout << "name = " << ft.name << "\t"
		<< "made = " << ft.made << "\t"
		<< "attempts = " << ft.attempts << "\t"
		<< "percent = " << ft.percent << "\n";
}

void set_pc(free_throws &ft)
{
	if (ft.attempts != 0)
	{
		ft.percent = 100.0f*float(ft.made) / float(ft.attempts);
	}
	else
	{
		ft.percent = 0.0;
	}
}

free_throws & accumulate(free_throws & target, const free_throws & source)
{
	target.attempts += source.attempts;
	target.made += source.made;
	return target;
}